package com.scs.application.modules.sys.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.cfg.utils.ParameterUtils;
import com.scs.application.modules.sys.entity.User;
import com.scs.application.modules.sys.model.RestResult;
import com.scs.application.modules.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@RestController
@RequestMapping("/print-worker")
public class PrintServiceController extends CrudController<UserService, User> {

    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("/print")
    public RestResult print(@RequestBody Map map) {

        String url = ParameterUtils.getString("print-worker.url");
        if (StringUtils.isBlank(url)) {
            logger.warn("打印服务地址参数还未配置，请在配置文件或通用参数配置界面配置。例：print-worker.url = http://127.0.0.1:8888/PrintWorker/MasoPrint/PrintByTemplet");
            return RestResult.ok("系统还未配置打印服务地址参数");
        }
        // String url = "http://127.0.0.1:8888/PrintWorker/MasoPrint/PrintByTemplet";

        ResponseEntity<RestResult> responseEntity = restTemplate.postForEntity(url, map, RestResult.class);
        return responseEntity.getBody();
    }

}
